package com.shareware.common.memory.entity

import com.shareware.common.utils.safeLet
import org.json.JSONObject

/**
 * desc: 功能描述
 * email: mobiledeveloper@qq.com
 */
data class PssInfo(
    var totalPssK: Int = -1,
    var pssJavaK: Int = -1,
    var pssNativeK: Int = -1,
    var pssGraphicK: Int = -1,
    var pssSystemK: Int = -1,
    var pssSwapK: Int = -1,
    var pssCodeK: Int = -1,
    var pssStackK: Int = -1,
    var pssPrivateOtherK: Int = -1,
) {
    override fun toString(): String {
        return String.format(
            "%-21s %-21s %-21s %-21s %-21s %-21s %-21s %-21s %-21s",
            "totalPss=$totalPssK K",
            "Java=$pssJavaK K",
            "Native=$pssNativeK K",
            "Graphic=$pssGraphicK K",
            "System=$pssSystemK K",
            "Swap=$pssSwapK K",
            "Code=$pssCodeK K",
            "Stack=$pssStackK K",
            "PrivateOther=$pssPrivateOtherK K"
        )
    }

    fun toJson() = safeLet(defVal = JSONObject()) {
        JSONObject().apply {
            put("total", totalPssK)
            put("java", pssJavaK)
            put("native", pssNativeK)
            put("graphic", pssGraphicK)
            put("system", pssSystemK)
            put("swap", pssSwapK)
            put("code", pssCodeK)
            put("stack", pssStackK)
            put("other", pssPrivateOtherK)
        }
    }
}